/*
 *    Copyright 2008-2009 The Digester Tools Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.digestertools.annotations.employee;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.digester.Digester;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import com.digestertools.annotations.DigesterLoader;

/**
 * 
 * @author Simone Tripodi
 * @version $Id: EmployeeTestCase.java 357 2009-12-16 20:00:36Z simone.tripodi $
 */
public final class EmployeeTestCase {

    @Test
    public void testEmployeeCreationFromXml() throws IOException, SAXException {
        Employee employee = new Employee();
        employee.setFirstName("First Name");
        employee.setLastName("Last Name");

        Address address = new Address();
        address.setCity("Home City");
        address.setState("HS");
        address.setStreet("Home Street");
        address.setType("home");
        address.setZipCode("HmZip");
        address.setEmployee(employee);

        address = new Address();
        address.setCity("Office City");
        address.setState("OS");
        address.setStreet("Office Street");
        address.setType("office");
        address.setZipCode("OfZip");
        address.setEmployee(employee);

        Digester digester = DigesterLoader.createDigester(Employee.class);
        DigesterLoader.addRules(Address.class, digester);

        InputStream input = getClass().getResourceAsStream("Employee.xml");

        Employee actual = (Employee) digester.parse(input);

        assert employee.equals(actual) : "Expected <"
            + employee
            + "> but found <"
            + actual
            + ">";
    }

}
